package com.sxbang.friday.dao;

import com.sxbang.friday.model.SysUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDao {
	/**
	 * 通过用户名获取用户
	 * @param username
	 * @return
	 */
	@Select("select * from sys_user t where t.username = #{username}")
	SysUser getUser(String username);

	/**
	 * 获取user总数
	 * @return
	 */
	@Select("select count(*) from sys_user t")
	Long countAllUsers();

	/**
	 * 分页获取users
	 * @param startPosition
	 * @param limitPosition
	 * @return
	 */
	@Select("select * from sys_user t order by t.id limit #{startPosition},#{limitPosition}")
	List<SysUser> getAllUsersByPage(@Param("startPosition") Integer startPosition,@Param("limitPosition") Integer limitPosition);

	//主键自增，传入对象，自动适配
	@Options(useGeneratedKeys = true,keyProperty="id")
	@Insert("insert into sys_user(username, password, nickname, headImgUrl, phone, telephone, email, birthday, sex, status, createTime, updateTime) values(#{username}, #{password}, #{nickname}, #{headImgUrl}, #{phone}, #{telephone}, #{email}, #{birthday}, #{sex}, #{status}, now(), now())")
    int save(SysUser sysUser);
}
